package dev.alm.meituanservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dev.alm.meituanservice.entity.Food;
import dev.alm.meituanservice.mapper.FoodMapper;
import dev.alm.meituanservice.service.FoodService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FoodServiceImpl implements FoodService {

    @Resource
    private FoodMapper foodMapper;

    @Override
    public Food addFood(Food food) {
        int insert = foodMapper.insert(food);
        if (insert == 0) {
            return null;
        }
        return foodMapper.selectById(food.getId());
    }

    @Override
    public List<Food> getFoodListByCategoryCode(String categoryCode) {
        QueryWrapper<Food> wrapper = new QueryWrapper<>();
        wrapper.eq("category_code", categoryCode);
        return foodMapper.selectList(wrapper);
    }

    @Override
    public List<Food> getFoodList() {
        return foodMapper.selectList(null);
    }

}
